package info.matsumana.sandbox;

import com.mysql.fabric.jdbc.FabricMySQLConnection;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Fabricサーバに接続してデータを削除するツール
 *
 * @author matsumana
 */
public class Delete extends DatabaseAccess {

    public static void main(String... args) {

        String a_sql = "DELETE FROM a WHERE column_2 = ?";
        String b_sql = "DELETE FROM b WHERE column_2 = ?";

        String c_sql = "DELETE FROM c WHERE column_14 = ?";

        FabricMySQLConnection conn = null;
        try {
            conn = getConnection();
            PreparedStatement ps = conn.prepareStatement(a_sql);
            for (int i = 1; i < 100; i++) {
                conn.setShardKey(String.valueOf(i));
                ps.setInt(1, i);
//                ps.setString(1, "afd");
                System.out.println("这是第" + i + "ge");
                ps.executeUpdate();
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        } finally {
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
